package com.mentaleye.biz.impl;

import com.mentaleye.bean.EmploymentTestimonialsBean;
import com.mentaleye.biz.EmploymentTestimonialsBiz;
import com.mentaleye.dal.model.EmploymentTestimonialsExample;
import com.mentaleye.service.EmploymentTestimonialsService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by hdg on 2017/6/6.
 */
@Service
public class EmploymentTestimonialsBizImpl implements EmploymentTestimonialsBiz {

    private static Logger logger = Logger.getLogger(EmploymentTestimonialsBizImpl.class);

    @Autowired private EmploymentTestimonialsService employmentservice;

    public CommonResult add(EmploymentTestimonialsBean bean) {
        CommonResult result = new CommonResult();
        boolean success = false;
        try{
            if(bean.getRecollectionsId() != null){
                success = employmentservice.edit(bean);
            }else{
                success = employmentservice.add(bean);
            }
            result.setIsSuccess(success);
        }catch (Exception e){
            logger.error("感言记录异常",e);
        }
        return result;
    }

    public CommonResult removeList(List<Integer> ids) {
        CommonResult result = new CommonResult();
        boolean success = false;
        try {
            EmploymentTestimonialsExample example = new EmploymentTestimonialsExample();
            example.createCriteria().andRecollectionsIdIn(ids);
            success = employmentservice.removeExample(example);
            result.setIsSuccess(success);
        }catch (Exception e){
            logger.error("批量删除感言记录异常",e);
        }
        return result;
    }

    public List<Map<String, Object>> query(EmploymentTestimonialsBean bean) {
        try {
            return employmentservice.queryById(bean);
        }catch (Exception e){
            logger.error("查询感言记录的学生异常",e);
        }
        return null;
    }

    public void queryCommPage(CommonPage commonPage) {
        try{
            employmentservice.queryByCommpage(commonPage);
        }catch (Exception e){
            logger.error("分页查询感言记录列表异常",e);
        }
    }

    public List<Map<String, Object>> queryByStudent() {
        try {
            return employmentservice.queryByStudent();
        }catch (Exception e){
            logger.error("查询入职的学生异常",e);
        }
        return null;
    }
}
